# TODO: create an attr_accessible method and make all but a few attributes writable

module Lypp
  class User < Base
    has_many :conferences
    has_many :contacts

    class << self
      # use the credentials in config/lypp.yml to authenticate and return a Lypp::User object
      def authenticate
        find user_id
      end
    end

    # a list of the user's conferences as Lypp::Conference objects
    #def conferences
    #  super
    #end

    # a list of this user's contacts as Lypp::Contact objects
    #def contacts
    #  super
    #end

    # the user's address
    def address
      attributes['address']
    end

    # set the user's address
    def address=(new_address)
      attributes['address'] = new_address
    end

    # the user's id
    def id
      super
    end

#    def id=(*args) #:nodoc:
#      raise Lypp::ReadOnlyError, 'the id is read-only'
#    end

    # the date the user was created
    def created_at
      super
    end

    def created_at=(*args) #:nodoc:
      raise Lypp::ReadOnlyError, 'the created_at is read-only'
    end

    # the date the user was updated
    def updated_at
      super
    end

    def updated_at=(*args) #:nodoc:
      raise Lypp::ReadOnlyError, 'the updated_at is read-only'
    end

    # the user's name
    def name
      super
    end

    # set the user's name
    def name=(new_name)
      super new_name
    end

    # the user's email address
    def email
      super
    end

    # set the user's email address
    def email=(new_email)
      super new_email
    end

    # the user's phone number
    def phone_number
      super
    end

    # set the user's phone number
    def phone_number=(new_phone_number)
      super new_phone_number
    end

    def password #:nodoc:
      raise Lypp::WriteOnlyError, 'the password is write-only'
    end

    # set the user's password
    def password=(new_password)
      super new_password
    end

    def password_confirmation #:nodoc:
      raise Lypp::WriteOnlyError, 'the password_confirmation is write-only'
    end

    # set the user's password confirmation
    def password_confirmation=(new_password)
      super new_password
    end

    # the user's instant messaging account
    def im
      super
    end

    # set the user's instant messaging account
    def im=(new_im)
      super new_im
    end

    # the user's instant messaging network
    def im_network
      super
    end

    # set the user's instant messaging network
    def im_network=(new_im_network)
      super new_im_network
    end

    # true if the user's instant messaging account has been authenticated
    def im_authenticated
      super
    end

    def im_authenticated=(*args) #:nodoc:
      raise Lypp::ReadOnlyError, 'the im_authenticated is read-only'
    end

    # the user's balance in seconds
    def balance_in_seconds
      super
    end

    def balance_in_seconds=(*args) #:nodoc:
      raise Lypp::ReadOnlyError, 'the balance_in_seconds is read-only'
    end

    # the user's time zone
    def time_zone
      super
    end

    # set the user's time zone
    def time_zone=(new_time_zone)
      super new_time_zone
    end
  end
end
